#region
/* Adoor.NET - Object/Relational mapping framework leveraging ADO.NET`s powerful disconnected mode.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *  
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *  
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */ 
#endregion

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using Adoor.Object.Domain;
using Adoor.Object.Query;

namespace Adoor.Object
{
	public delegate void ObjectSourceRetryEventHandler(object sender, ObjectSourceRetryEventArgs e);

	public class ObjectSourceRetryEventArgs : EventArgs
	{
		public ObjectSourceRetryEventArgs(bool retry, Exception ex)
		{
			this.retry = retry;
			this.ex = ex;
			this.handled = false;
		}

		private bool retry;
		public bool Retry
		{
			get{ return retry; }
			set{ retry = value; }
		}

		private bool handled;
		public bool Handled
		{
			get{ return handled; }
			set{ handled = value; }
		}

		private Exception ex;
		public Exception Exception
		{
			get{ return ex;}
		}
	}

	/// <summary>
	/// Interface supported by components capable to execute <see cref="ObjectQuery"/> queries.
	/// </summary>
	public interface IObjectSource : IDisposable
	{
        IObjectResolver ObjectResolver { get; set; }        

		/// <summary>
		/// Fills the <c>dataset</c> with all entities of type <c>type</c>.
		/// </summary>
		/// <param name="dataset">The DataSet object to be filled.</param>
		/// <param name="type">The type of entities to fill the dataset with.</param>
		void Fill(DataSet dataset, Type type);

		/// <summary>
		/// Fills the dataset with the result of the query.
		/// </summary>
		/// <param name="dataset">The DataSet object to be filled.</param>
		/// <param name="query">The query whose result fills the dataset.</param>
		/// <param name="args">Arguments used by the query.</param>
		void Fill(DataSet dataset, ObjectQuery query, params object[] args);

		/// <summary>
		/// Fills the dataset with the result of the query.
		/// </summary>
		/// <param name="dataset">The DataSet object to be filled.</param>
		/// <param name="query">The query whose result fills the dataset.</param>
		/// <param name="args">Arguments used by the query.</param>
		void Fill(DataSet dataset, string query, params object[] args);

		/// <summary>
		/// Fills the dataset with the result of the query.
		/// </summary>
		/// <param name="dataset">The DataSet object to be filled.</param>
		/// <param name="query">The query whose result fills the dataset.</param>
		/// <param name="args">Arguments used by the query.</param>
		void Fill(DataSet dataset, string query, IDictionary<string, object> args);

		/// <summary>
		/// Fills the table named <c>tableName</c> in the <c>dataset</c> with all entities of type <c>type</c>.
		/// </summary>
		/// <param name="dataset">The DataSet object to be filled.</param>
		/// <param name="tableName">The name of the DataTable inside the dataset that will contain the result.</param>
		/// <param name="type">The type of entities to fill the dataset with.</param>
		void Fill(DataSet dataset, string tableName, Type type);

		/// <summary>
		/// Fills the table named <c>tableName</c> in the <c>dataset</c> with the result of the query.
		/// </summary>
		/// <param name="dataset">The DataSet object to be filled.</param>
		/// <param name="tableName">The name of the DataTable inside the dataset that will contain the result.</param>
		/// <param name="query">The query whose result fills the dataset.</param>
		/// <param name="args">Arguments used by the query.</param>
		void Fill(DataSet dataset, string tableName, ObjectQuery query, params object[] args);

		/// <summary>
		/// Fills the table named <c>tableName</c> in the <c>dataset</c> with the result of the query.
		/// </summary>
		/// <param name="dataset">The DataSet object to be filled.</param>
		/// <param name="tableName">The name of the DataTable inside the dataset that will contain the result.</param>
		/// <param name="query">The query whose result fills the dataset.</param>
		/// <param name="args">Arguments used by the query.</param>
		void Fill(DataSet dataset, string tableName, string query, params object[] args);

		/// <summary>
		/// Fills the <c>table</c> with all entities of type <c>type</c>.
		/// </summary>
		/// <param name="table">The DataTable object to be filled.</param>
		/// <param name="type">The type of entities to fill the dataset with.</param>
		void Fill(DataTable table, Type type);

		/// <summary>
		/// Fills the <c>table</c> with the result of the query.
		/// </summary>
		/// <param name="table">The DataTable object to be filled.</param>
		/// <param name="query">The query whose result fills the dataset.</param>
		/// <param name="args">Arguments used by the query.</param>
		void Fill(DataTable table, ObjectQuery query, params object[] args);

		/// <summary>
		/// Fills the <c>table</c> with the result of the query.
		/// </summary>
		/// <param name="table">The DataTable object to be filled.</param>
		/// <param name="query">The query whose result fills the dataset.</param>
		/// <param name="args">Arguments used by the query.</param>
		void Fill(DataTable table, string query, params object[] args);

        void Fill(DataTable table, string query, IDictionary<string, object> args);

        void Fill(DataTable table, ObjectQuery query, IDictionary<string, object> args);

		Int64 GetCount(Type type);
		Int64 GetCount(ObjectQuery query, params object[] args);
		Int64 GetCount(string query, params object[] args);
		IDataReader GetDataReader(Type type);
		IDataReader GetDataReader(ObjectQuery query, params object[] args);
		IDataReader GetDataReader(string query, params object[] args);

		object GetScalar(ObjectQuery query, params object[] args);
		object GetScalar(string query, params object[] args);

		void Delete(object entity);  // TODO: in Adoor.Object.Entity
		void DeleteAll(Type type);
		void DeleteAll(ObjectPath path, params object[] args);
		void DeleteAll(string query, params object[] args);
//
//		void Update(string query, params object[] args);
//		void Update(ObjectQuery query, params object[] args);

        void ExecuteNonQuery(string query, IDictionary<string, object> args);
        void ExecuteNonQuery(ObjectQuery query, IDictionary<string, object> args);		
		void ExecuteNonQuery(string query, params object[] args);
		void ExecuteNonQuery(ObjectQuery query, params object[] args);

		event ObjectSourceRetryEventHandler ObjectSourceRetry;
	}

}